package com.zhiwei.jenkins.common.enums;

/**
 * @Description: 响应码
 * @Author: wyjun
 * @UpdateDate: 2019/11/14 9:57
 * @Version: 1.0
 */
public enum ResponseCode {

    /** 成功类 */
    /**
     * 成功响应
     */
    SUCCESS(200, "Success", "成功"),

    /** 错误类 */
    /**
     * 400:参数错误
     */
    PARAM_ERROR(400, "ParamError", "参数错误", 110001),
    MAX_UPLOAD_SIZE_EXCEEDED_EXCEPTION(400, "MaxUploadSizeExceededException", "上传文件或请求参数超出最大长度"),
    /**
     * 用户名或密码错误
     */
    INVALID_CERT_ACCOUNT(401, "InvalidCertAccount", "用户名或密码错误"),

    /**
     * 401:应用验证不通过
     */
    INVALID_APP(401, "InvalidApp", "验证码错误"),

    /**
     * 令牌无效 - 提交的凭据与预期的凭据不匹配
     */
    UNAUTHORIZED(401, "Unauthorized", "令牌无效 - 提交的凭据与预期的凭据不匹配"),

    /**
     * 请求错误，请稍后再试
     */
    REQUESTERROR(500, "RequestError", "请求错误，请稍后再试"),
    /**
     * 内部错误 （数据库访问异常等）
     */
    INTERNAL_ERROR(500, "InternalError", "内部错误"),
    /*** 全局业务异常大类 */
    EXCEPTION_BUSINESS(500, "ExceptionBusiness", "业务异常", 100100),
    EXCEPTION_BUSINESS_PARAM_MISS(400, "ExceptionBusinessParamMiss", "参数缺失", 100101),
    /*** 代码出现异常 */
    EXCEPTION_UNKWOWN(500, "ExceptionUnkwown", "服务繁忙，请稍后再试", 100200),
    EXCEPTION_BS(500, "ExceptionBS", "系统基础服务异常", 100300),
    /*** 调用远程接口出现异常 */
    EXCEPTION_RPC(500, "ExceptionRPC", "远程服务调用异常", 100400),
    DEFAULT(200, "Success", "成功");

    /**
     * http错误码
     */
    private int httpCode;

    /**
     * 系统错误码
     */
    private String errorCode;

    /**
     * 消息
     */
    private String msg;

    /**
     * 微服务错误码
     */
    private Integer serviceCode;

    ResponseCode(int httpCode, String errorCode, String msg) {
        this.httpCode = httpCode;
        this.errorCode = errorCode;
        this.msg = msg;
    }

    ResponseCode(int httpCode, String errorCode, String msg, Integer serviceCode) {
        this.httpCode = httpCode;
        this.errorCode = errorCode;
        this.msg = msg;
        this.serviceCode = serviceCode;
    }

    public static ResponseCode getResponseCodeByServiceCode(Integer serviceCode) {
        ResponseCode[] values = ResponseCode.values();
        if (serviceCode != null) {
            for (int i = 0; i < values.length; i++) {
                if (serviceCode.equals(values[i].serviceCode)) {
                    return values[i];
                }
            }
        }
        return REQUESTERROR;
    }

    public int getHttpCode() {
        return httpCode;
    }

    public void setHttpCode(int httpCode) {
        this.httpCode = httpCode;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Integer getServiceCode() {
        return serviceCode;
    }

    public void setServiceCode(Integer serviceCode) {
        this.serviceCode = serviceCode;
    }
}
